package com.xiaoli.algebra;

// $ANTLR 3.4 C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g 2012-06-06 17:33:52

import org.antlr.runtime.BitSet;
import org.antlr.runtime.MismatchedSetException;
import org.antlr.runtime.Parser;
import org.antlr.runtime.ParserRuleReturnScope;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.RecognizerSharedState;
import org.antlr.runtime.Token;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTreeAdaptor;
import org.antlr.runtime.tree.TreeAdaptor;


@SuppressWarnings({"all", "warnings", "unchecked"})
public class AlgebraParser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "INT", "'*'", "'+'", "'-'", "'/'"
    };

    public static final int EOF=-1;
    public static final int T__5=5;
    public static final int T__6=6;
    public static final int T__7=7;
    public static final int T__8=8;
    public static final int INT=4;

    // delegates
    public Parser[] getDelegates() {
        return new Parser[] {};
    }

    // delegators


    public AlgebraParser(TokenStream input) {
        this(input, new RecognizerSharedState());
    }
    public AlgebraParser(TokenStream input, RecognizerSharedState state) {
        super(input, state);
    }

protected TreeAdaptor adaptor = new CommonTreeAdaptor();

public void setTreeAdaptor(TreeAdaptor adaptor) {
    this.adaptor = adaptor;
}
public TreeAdaptor getTreeAdaptor() {
    return adaptor;
}
    public String[] getTokenNames() { return AlgebraParser.tokenNames; }
    public String getGrammarFileName() { return "C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g"; }


    public static class addExpr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "addExpr"
    // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:4:1: addExpr : multExpr ( ( '+' | '-' ) multExpr )* ;
    public final AlgebraParser.addExpr_return addExpr() throws RecognitionException {
        AlgebraParser.addExpr_return retval = new AlgebraParser.addExpr_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token set2=null;
        AlgebraParser.multExpr_return multExpr1 =null;

        AlgebraParser.multExpr_return multExpr3 =null;


        Object set2_tree=null;

        try {
            // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:4:9: ( multExpr ( ( '+' | '-' ) multExpr )* )
            // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:4:12: multExpr ( ( '+' | '-' ) multExpr )*
            {
            root_0 = (Object)adaptor.nil();


            pushFollow(FOLLOW_multExpr_in_addExpr18);
            multExpr1=multExpr();

            state._fsp--;

            adaptor.addChild(root_0, multExpr1.getTree());

            // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:4:21: ( ( '+' | '-' ) multExpr )*
            loop1:
            do {
                int alt1=2;
                int LA1_0 = input.LA(1);

                if ( ((LA1_0 >= 6 && LA1_0 <= 7)) ) {
                    alt1=1;
                }


                switch (alt1) {
            	case 1 :
            	    // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:4:22: ( '+' | '-' ) multExpr
            	    {
            	    set2=(Token)input.LT(1);

            	    if ( (input.LA(1) >= 6 && input.LA(1) <= 7) ) {
            	        input.consume();
            	        adaptor.addChild(root_0, 
            	        (Object)adaptor.create(set2)
            	        );
            	        state.errorRecovery=false;
            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        throw mse;
            	    }


            	    pushFollow(FOLLOW_multExpr_in_addExpr27);
            	    multExpr3=multExpr();

            	    state._fsp--;

            	    adaptor.addChild(root_0, multExpr3.getTree());

            	    }
            	    break;

            	default :
            	    break loop1;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "addExpr"


    public static class multExpr_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };


    // $ANTLR start "multExpr"
    // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:6:1: multExpr : INT ( ( '*' | '/' ) INT )* ;
    public final AlgebraParser.multExpr_return multExpr() throws RecognitionException {
        AlgebraParser.multExpr_return retval = new AlgebraParser.multExpr_return();
        retval.start = input.LT(1);


        Object root_0 = null;

        Token INT4=null;
        Token set5=null;
        Token INT6=null;

        Object INT4_tree=null;
        Object set5_tree=null;
        Object INT6_tree=null;

        try {
            // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:7:2: ( INT ( ( '*' | '/' ) INT )* )
            // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:7:5: INT ( ( '*' | '/' ) INT )*
            {
            root_0 = (Object)adaptor.nil();


            INT4=(Token)match(input,INT,FOLLOW_INT_in_multExpr41); 
            INT4_tree = 
            (Object)adaptor.create(INT4)
            ;
            adaptor.addChild(root_0, INT4_tree);


            // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:7:9: ( ( '*' | '/' ) INT )*
            loop2:
            do {
                int alt2=2;
                int LA2_0 = input.LA(1);

                if ( (LA2_0==5||LA2_0==8) ) {
                    alt2=1;
                }


                switch (alt2) {
            	case 1 :
            	    // C:\\cygwin\\home\\yywill\\workspaces\\antlr\\Algebra.g:7:10: ( '*' | '/' ) INT
            	    {
            	    set5=(Token)input.LT(1);

            	    if ( input.LA(1)==5||input.LA(1)==8 ) {
            	        input.consume();
            	        adaptor.addChild(root_0, 
            	        (Object)adaptor.create(set5)
            	        );
            	        state.errorRecovery=false;
            	    }
            	    else {
            	        MismatchedSetException mse = new MismatchedSetException(null,input);
            	        throw mse;
            	    }


            	    INT6=(Token)match(input,INT,FOLLOW_INT_in_multExpr50); 
            	    INT6_tree = 
            	    (Object)adaptor.create(INT6)
            	    ;
            	    adaptor.addChild(root_0, INT6_tree);


            	    }
            	    break;

            	default :
            	    break loop2;
                }
            } while (true);


            }

            retval.stop = input.LT(-1);


            retval.tree = (Object)adaptor.rulePostProcessing(root_0);
            adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
        catch (RecognitionException re) {
            reportError(re);
            recover(input,re);
    	retval.tree = (Object)adaptor.errorNode(input, retval.start, input.LT(-1), re);

        }

        finally {
        	// do for sure before leaving
        }
        return retval;
    }
    // $ANTLR end "multExpr"

    // Delegated rules


 

    public static final BitSet FOLLOW_multExpr_in_addExpr18 = new BitSet(new long[]{0x00000000000000C2L});
    public static final BitSet FOLLOW_set_in_addExpr21 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_multExpr_in_addExpr27 = new BitSet(new long[]{0x00000000000000C2L});
    public static final BitSet FOLLOW_INT_in_multExpr41 = new BitSet(new long[]{0x0000000000000122L});
    public static final BitSet FOLLOW_set_in_multExpr44 = new BitSet(new long[]{0x0000000000000010L});
    public static final BitSet FOLLOW_INT_in_multExpr50 = new BitSet(new long[]{0x0000000000000122L});

}